import { createRouter, createWebHashHistory, createWebHistory } from "vue-router";
import { qiankunWindow } from 'vite-plugin-qiankun/dist/helper'
import packagejson from "../../package.json";

const routes = [
  {
    path: "/",
    // redirect: '/home',
    component: () => import("@/views/Home/index.vue"),
    children: [
      {
        path: "home",
        name: "home",
        component: () => import("@/views/Home/index.vue"),
      },
    ],
  }
];

const useRouter = () => {
  const base = qiankunWindow.__POWERED_BY_QIANKUN__ ? `${packagejson.name}` : ''
  return createRouter({
    history: createWebHistory(base),
    routes: routes,
    scrollBehavior(to, from, savedPosition) {
      if (savedPosition) {
        return savedPosition
      } else {
        return { top: 0 }
      }
    },
  });
}

const router = useRouter()
export default router